package com.demo.controller;


import java.io.Console;
import java.util.List;

import com.demo.annotation.GlobalInterceptor;
import com.demo.annotation.VerifyParam;
import com.demo.entity.constants.Constants;
import com.demo.entity.dto.SessionWebUserDto;
import com.demo.entity.enums.AppiontmentStatusEnum;
import com.demo.entity.enums.UserRoleTypeEnum;
import com.demo.entity.po.Appointment;

import com.demo.entity.query.AppointmentQuery;


import com.demo.entity.vo.ResponseVO;

import org.aspectj.apache.bcel.classfile.Constant;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.demo.service.AppointmentService;

/**
 * @Description:咨询预约表Controller
 * @Date:2025-03-01
 * @author：author
*/
@RestController
@RequestMapping("/appointment")
public class AppointmentController extends ABaseController {

	@Resource
	private AppointmentService appointmentService;

	/**
	 * 用户查询预约信息
	 */
	@RequestMapping("/loadAppointment4User")
	@GlobalInterceptor
	public ResponseVO loadAppointment4User(HttpSession session,
											   AppointmentQuery query) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		query.setUserId(webUserDto.getUserId());
		query.setOrderBy("update_time desc");
		return getSuccessResponseVO(appointmentService.findListByPage(query));
	}

	/**
	 * 心理师查询列表
	 */
	@RequestMapping("/loadAppointment4Counselor")
	@GlobalInterceptor(checkCounselor = true)
	public ResponseVO loadAppointment4Counselor(HttpSession session,
										   AppointmentQuery query) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		query.setCounselorId(webUserDto.getUserId());
		// 咨询师 查看 已确认 已完成 已驳回
		query.setStatsArray(new Integer[]{AppiontmentStatusEnum.COMFRMED.getStatus(),
				AppiontmentStatusEnum.REJECT.getStatus(),AppiontmentStatusEnum.COMPLETED.getStatus()});
		query.setOrderBy("update_time desc");
		return getSuccessResponseVO(appointmentService.findListByPage(query));
	}


	/**
	 * 保存预约信息
	 * @param session
	 * @param appointment
	 * @return
	 */
	@RequestMapping("/saveInfo")
	@GlobalInterceptor
	public 	ResponseVO saveInfo(HttpSession session,Appointment appointment) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		appointment.setUserId(webUserDto.getUserId());
		appointmentService.saveInfo(appointment);
		return getSuccessResponseVO(null);
	}

	/**
	 * 删除预约信息
	 * @param session
	 * @param appointmentId 预约id
	 * @return
	 */
	@RequestMapping("/delInfo")
	@GlobalInterceptor
	public 	ResponseVO delInfo(HttpSession session,@VerifyParam(required = true) Long appointmentId) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		AppointmentQuery appointmentQuery = new AppointmentQuery();
		appointmentQuery.setUserId(webUserDto.getUserId());
		appointmentQuery.setAppointmentId(appointmentId);
		appointmentService.deleteByParam(appointmentQuery);
		return getSuccessResponseVO(null);
	}


	/**
	 * 用户修改预约状态
	 * @param session
	 * @param appointmentId 预约id
	 * @param status 状态
	 * @return
	 */
	@RequestMapping("/updateStatus4User")
	@GlobalInterceptor
	public ResponseVO updateStatus(HttpSession session,
								   @VerifyParam(required = true) Long appointmentId,
								   @VerifyParam(required = true) Integer status) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		appointmentService.updateStatus(webUserDto.getUserId(),appointmentId,status, UserRoleTypeEnum.USER);
		return getSuccessResponseVO(null);
	}


	/**
	 * 咨询师修改状态
	 * @param session
	 * @param appointmentId 预约id
	 * @param status 状态
	 * @return
	 */
	@RequestMapping("/updateStatus4Counselor")
	@GlobalInterceptor(checkCounselor = true)
	public ResponseVO updateStatus4Counselor(HttpSession session,
								   @VerifyParam(required = true) Long appointmentId,
								   @VerifyParam(required = true) Integer status) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		appointmentService.updateStatus(webUserDto.getUserId(),appointmentId,status, UserRoleTypeEnum.COUNSELOR);
		return getSuccessResponseVO(null);
	}


}